package special;


import org.junit.Test;

import java.util.ArrayDeque;
import java.util.Stack;

public class LeetCode_1823 {

    public int findTheWinner(int n, int k) {
        return solution_1(n,k);
    }

    @Test
    public void test(){
        System.out.println(findTheWinner(6, 5));
    }

    private int solution_1(int n, int k) {
        ArrayDeque<Integer> deque = new ArrayDeque<>();
        Stack<Integer> stack = new Stack<>();
        //1. 加入deque
        for (int i = 1; i <= n; i++) {
            deque.addLast(i);
        }
        //2. 逐个弹出
        for (int i = 0; i < n-1; i++) {
            for (int j = 0; j < k-1; j++) {
                deque.addLast(deque.removeFirst());
            }
            deque.removeFirst();
        }
        return deque.pop();
    }

}
